<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class profile extends CI_Controller {

    function __construct() {
        parent::__construct();
        //dibikin dicek udah login apa belom, kalo udah di redirect ke controller user buat login
    }

    function index() {
        $action = $this->input->post('b_submit');
        if ($action == 'Update') {
            $this->update();
        } else if ($action == 'Logout') {
            $this->logout();
        } else if ($action == 'Reset Password') {
            $this->resetPass();
        }
    }
    
    function logout() {
        $this->m_session->destroy_session();
        $data = array('status' => '');
        $this->load->view("login",$data);
    }
    
    function update(){
        //load model
        $this->load->model('m_userid', '', TRUE);
        
        //Get data from form
        $email = $_POST['email'];
        $name = $_POST['name'];
        $date = $_POST['date'];
        $bio = $_POST['bio'];
        
        //Check email
        $query = $this->db->query("SELECT * FROM user WHERE email='$email'");

        $salt = '';
            
        $this->db->query("UPDATE user SET nama='$name', bio='$bio' WHERE email='$email'");

        $data['email'] = $email;
        $data['name'] = $name;
        $data['date'] = $date;
        $data['bio'] = $bio;
        $this->load->view('profile', $data);
        
    }
    
    function resetPass(){
        //blm di implementasi
    }
}
